﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FantastPlatform.Framework.IModel;
using FantastPlatform.Framework.Model;
using FantastPlatform.Framework.IService;
using FantastPlatform.Framework.Common;
using FantastPlatform.Framework.Core;

namespace FantastPlatform.Framework.Service
{
    public class StreetService : DataService<IStreet, Street>, IStreetService
    {

        public IList<IStreet> SearchStreet(string code, int pageSize, int pageNum, out int totalRecords)
        {
            ConditionGroup group = new ConditionGroup();
            Condition condition = new Condition();
            Condition enableCondition = new Condition() { Field = "Enable", Type = typeof(bool).FullName, Value1 = true };
            group.Conditions.Add(enableCondition);
            if (!string.IsNullOrEmpty(code))
            {

                if (Tools.IsChinese(code))
                {
                    condition = new Condition() { Field = "Name", Type = typeof(string).FullName, Value1 = code + "%", Comparison = Comparisons.Like };

                }
                else if (Tools.IsPinyin(code))
                {
                    condition = new Condition() { Field = "Pinyin", Type = typeof(string).FullName, Value1 = code + "%", Comparison = Comparisons.Like };
                }
                else
                    condition = new Condition() { Field = "Code", Type = typeof(string).FullName, Value1 = code + "%", Comparison = Comparisons.Like };
                group.Conditions.Add(condition);
            }


            return base.Search(group, null, pageSize, pageNum, out totalRecords);

        }
        public IList<IStreet> SearchStreet(string code, ConditionGroup group, int pageSize, int pageNum, out int totalRecords)
        {
            Condition condition = new Condition();
            if (group == null)
            {
                group = new ConditionGroup();
                Condition enableCondition = new Condition() { Field = "Enable", Type = typeof(bool).FullName, Value1 = true };
                group.Conditions.Add(enableCondition);

            }
            if (!string.IsNullOrEmpty(code))
            {

                if (Tools.IsChinese(code))
                {
                    condition = new Condition() { Field = "Name", Type = typeof(string).FullName, Value1 = code + "%", Comparison = Comparisons.Like };

                }
                else if (Tools.IsPinyin(code))
                {
                    condition = new Condition() { Field = "Pinyin", Type = typeof(string).FullName, Value1 = code + "%", Comparison = Comparisons.Like };
                }
                else
                    condition = new Condition() { Field = "Code", Type = typeof(string).FullName, Value1 = code + "%", Comparison = Comparisons.Like };
                group.Conditions.Add(condition);
            }


            return base.Search(group, null, pageSize, pageNum, out totalRecords);

        }


    }
}
